﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TheOutLetLibrary.Dominio;
using System.Data.OleDb;

namespace TheOutLetLibrary.Infraestrutura {

    public class Accessk_orderLineDAO : BaseDAO, IGenericDAO<k_orderLine> {

        public Accessk_orderLineDAO(OleDbTransaction transacao)
            : base(transacao) {
        }

        public int Inclua(k_orderLine entity) {

            OleDbCommand comando = GetCommand();
            comando.CommandText =
                " INSERT INTO k_orderLine ( " +
                " NR_PEDIDO, [name], variation, skuId, productId, quantity, " +
                " isKit, listPrice, salePrice, discount, totalAmount) " +
                " VALUES (" +
                " @NR_PEDIDO, @name, @variation, @skuId, @productId, @quantity, " +
                " @isKit, @listPrice, @salePrice, @discount, @totalAmount)";
            comando.Parameters.Add("@NR_PEDIDO", OleDbType.Integer).Value = entity.NR_PEDIDO;
            comando.Parameters.Add("@name", OleDbType.VarChar).Value = entity.name;
            comando.Parameters.Add("@variation", OleDbType.VarChar).Value = entity.variation;
            comando.Parameters.Add("@skuId", OleDbType.Integer).Value = entity.skuId;
            comando.Parameters.Add("@productId", OleDbType.VarChar).Value = entity.productId;
            comando.Parameters.Add("@quantity", OleDbType.VarChar).Value = entity.quantity.ToString();
            comando.Parameters.Add("@isKit", OleDbType.VarChar).Value = entity.isKit.ToString();
            comando.Parameters.Add("@listPrice", OleDbType.VarChar).Value = entity.listPrice.ToString();
            comando.Parameters.Add("@salePrice", OleDbType.VarChar).Value = entity.salePrice.ToString();
            comando.Parameters.Add("@discount", OleDbType.VarChar).Value = entity.discount.ToString();
            comando.Parameters.Add("@totalAmount", OleDbType.VarChar).Value = entity.totalAmount.ToString();
            comando.ExecuteNonQuery();

            comando.CommandText = "SELECT @@IDENTITY";
            entity.COD = Convert.ToInt32(comando.ExecuteScalar());
            return entity.COD;
        }

        public k_orderLine Ache(int Id) {
            throw new NotImplementedException();
        }
    }
}
